<?php
namespace Rac\Controller;
use Think\Controller;
class LoginController extends Controller {
	
	
	// 登录首页
    public function index(){       	
    	$this->display();
    }
    
    // 获取验证码
    public function get_verif_code() {
    	get_verify_code();
    }
    
    // 登录验证
    public function login() {
    	if(IS_AJAX) {
            $username = I('post.username');
            $password = I('post.password');
            //$verif_code = I('post.verif_code');
            
            $res = array('flag'=>0, 'msg'=>'');
            
            // 判断验证码是否正确
            //$bool = check_verify($verif_code);
            $bool = true;
            if ( $bool ) {
            	$admin = D('Admin')->getAdminInfo($username);
            	if (! empty($admin)) {
            		$password = enter_password($password);
            		if ($password == $admin['password']) {
            			session('admin', $admin);
            			$res['flag'] = 1;
            			D('Admin')->setLoginInfo($admin['id']);
            		} else {
            			$res['flag'] = -3;
            			$res['msg'] = L('_username_password_error_');
            		}
            	} else {
            		$res['flag'] = -2;
            		$res['msg'] = L('_username_error_');
            	}
            } else {
            	$res['flag'] = -1;
            	$res['msg'] = L('_verification_code_error_');
            }
            
            echo json_encode($res);
    	}          		
    }




    public function logout(){
		session('admin', null);
        header('location:' . U('Login/index'));   
    }
}